package cc.fine.svc.main.service.impl.tbl;

import cc.fine.svc.main.bean.po.RelVideoTag;
import cc.fine.svc.main.bean.po.TblTag;
import cc.fine.svc.main.mapper.TblTagMapper;
import cc.fine.svc.main.service.rel.RelVideoTagService;
import cc.fine.svc.main.service.tbl.TblTagService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wyihe
 * @since 2023-10-25
 */
@Service
public class TblTagServiceImpl extends ServiceImpl<TblTagMapper, TblTag> implements TblTagService {

    @Autowired
    private RelVideoTagService relVideoTagService;

    @Override
    public List<String> getVideoIds(String tagId) {
        QueryWrapper<RelVideoTag> w = new QueryWrapper<>();
        w.eq("tag_id", tagId);

        return relVideoTagService.list(w).stream()
                .map(x -> x.getVideoId())
                .collect(Collectors.toList());

    }

    @Override
    public List<TblTag> getTags(String videoId) {
        List<TblTag> res = baseMapper.gatTags(videoId);
        if (res == null) res = new ArrayList<>();
        return res;
    }
}
